/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.clarice.homechef.controllers;

import com.clarice.homechef.constants.Constants;
import com.clarice.homechef.domain.User;
import com.clarice.homechef.utils.Utility;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author Akshay Velhal
 */
@RestController
@RequestMapping("/api")
public class UIElementController {

    @Autowired
    Utility utility;

    @RequestMapping(value = "/mealnames", method = RequestMethod.GET)
    public List<String> getAllMealsNames(
            HttpServletResponse response,
            @RequestHeader(Constants.NT_LOGIN) String userName) throws Exception {
        System.out.println("Get: All meals names for: " + userName);
        List<String> mealsNames = utility.getMealNames();
        System.out.println("Returning all meals names for " + userName + " and Names: " + mealsNames);
        return mealsNames;
    }

    @RequestMapping(value = "/userlogin", method = RequestMethod.POST)
    public @ResponseStatus(value = HttpStatus.CREATED) User isValidUser(
            HttpServletResponse response,
            @RequestHeader(Constants.NT_LOGIN) String userName) throws Exception {
        System.out.println("Post: is valid user: " + userName);
        String name = utility.isValidUser(userName);
        User user = new User();
        user.setName(name);
        return user;
    }
    
    @RequestMapping(value = "/cheflogin", method = RequestMethod.POST)
    public @ResponseStatus(value = HttpStatus.CREATED) User isValidChef(
            HttpServletResponse response,
            @RequestHeader(Constants.NT_LOGIN) String userName) throws Exception {
        System.out.println("Post: is valid chef: " + userName);
        String name = utility.isValidChef(userName);
        User user = new User();
        user.setName(name);
        return user;
    }
}
